﻿using LxCore;
using System;
using System.Reflection;

namespace LxCore
{
    public class FvZoneList : JsIdentifyList<FvZone>
    {
        public override void Add(FvZone item)
        {
            base.Add(item);
            if (isSimMesh())
            {
                LxSim.Sim.Conditions.ZoneConds.Add(new ZoneCond(item));
                LxSim.Sim.Fields.ZoneFields.Add(new ZoneCFDFields(item));
            }
        }
        public override void Insert(int index, FvZone item)
        {
            base.Insert(index, item);
            if (isSimMesh())
            {
                LxSim.Sim.Conditions.ZoneConds.Insert(index, new ZoneCond(item));
                LxSim.Sim.Fields.ZoneFields.Insert(index, new ZoneCFDFields(item));
            }
        }
        public override void RemoveAt(int index)
        {
            base.RemoveAt(index);
            if (isSimMesh())
            {
                LxSim.Sim.Conditions.ZoneConds.RemoveAt(index);
                LxSim.Sim.Fields.ZoneFields.RemoveAt(index);
            }
        }
        public override bool Remove(FvZone item)
        {
            throw new NotImplementedException();
            return base.Remove(item);
        }
        public override void Clear()
        {
            base.Clear();
            if (isSimMesh())
            {
                LxSim.Sim.Conditions.ZoneConds.Clear();
                LxSim.Sim.Fields.ZoneFields.Clear();
            }
        }
        protected bool isSimMesh()
        {
            return ReferenceEquals(this, LxSim.Sim.Mesh.Zones);
        }
    }
}
